package com.sunshine.wrongquestionset.room.entity

import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.Index
import androidx.room.PrimaryKey

/**
 * @author sunshine
 * @date 2021/3/28
 * 错题集实体类，相当于用户根据自己的习惯进行分类
 */
@Entity(
    tableName = "question_set",
    foreignKeys = [
        ForeignKey(
            entity = UserEntity::class,
            parentColumns = ["id"],
            childColumns = ["userId"],
            onDelete = ForeignKey.CASCADE,
            onUpdate = ForeignKey.CASCADE
        ),
        //2021 04 10更新：今天更变了逻辑：科目下属错题本，所以增加了外键
        ForeignKey(
            entity = SubjectEntity::class,
            parentColumns = ["id"],
            childColumns = ["subjectId"],
            onDelete = ForeignKey.CASCADE,
            onUpdate = ForeignKey.CASCADE
        )
    ],
    indices = [
        Index("userId"),
        Index("subjectId")
    ]
)
class QuestionSetEntity(
    @PrimaryKey(autoGenerate = true)
    val id: Int,
    val userId: String,
    var name: String,
    //错题本的说明
    var description: String?,

    //2021 04 10更新：今天更变了逻辑：科目下属错题本，所以增加了外键
    //默认值为-1，表示未知科目
    var subjectId: Int,

    //2021 04 10更新：错题本新增背景颜色存储
    //显示在界面上错题本的背景颜色，默认为浅蓝
    var backgroundColor: String = "#8AB4F8"
) {
    override fun toString(): String {
        return "QuestionSetEntity(id=$id, userId='$userId', name='$name', description=$description, subjectId=$subjectId, backgroundColor='$backgroundColor')"
    }
}